﻿using DataConnector;
using Equin.ApplicationFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LabManager.Forms
{
    public partial class ObjectsForm : Form
    {
        public int ProductID { get; set; }
        public int Amount { get; set; }

        public ObjectsForm()
        {
            InitializeComponent();
        }

        private void ObjectsForm_Load(object sender, EventArgs e)
        {
            LoadProducts();
        }

        #region Events

        private void btOk_Click(object sender, EventArgs e)
        {
            Amount = int.Parse(udAmount.Text);
            ProductID = (int)cbProducts.SelectedValue;

            Close();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        #endregion

        #region Helper

        public void LoadProducts()
        {
            var products = new BindingListView<V_Product>(DataConnectorLayer.Instance.R_V_Product.FindAll(x => x.ProductID > 0).ToList<V_Product>());

            cbProducts.DataSource = products;
            cbProducts.ValueMember = "ProductID";
            cbProducts.DisplayMember = "ProductDescription";
        }

        #endregion
    }
}
